import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created by 齐力锋 on 2017/5/16.
 */

public class transform {
    public String testString;
    private Stack<Character> stack;
    ArrayList<Character> List = new ArrayList(1000);
    public String String;
    public transform() {
        this.stack = new Stack<Character>();
        System.out.println("请输入您的中缀表达式");
         Scanner scan = new Scanner(System.in);
        testString = scan.nextLine();
        System.out.println("您输入的是" + testString);
    }


    public String transform() {


        for (int i = 0; i < testString.length(); i++) {
            char c = testString.charAt(i);

            if (c == '+' || c == '-') {
                if (stack.isEmpty() || stack.peek().equals('(')) {
                    stack.push(c);
                } else {
                    while (!stack.isEmpty() && (stack.peek().equals('*') || stack.peek().equals('/') || stack.peek().equals('+') || stack.peek().equals('-'))) {

                        List.add((stack.pop()));
                    }
                    stack.push(c);
                }

            } else if (c == '*' || c == '/') {
                if (stack.isEmpty() || stack.peek().equals('(')) {
                    stack.push(c);
                } else {
                    while (!stack.isEmpty() && (stack.peek().equals('*') || stack.peek().equals('/'))) {

                        List.add(stack.pop());
                    }

                    stack.push(c);
                }
            } else if (c == '(') {
                stack.push(c);
            } else if (c == ')') {

                while (!stack.peek().equals('(')) {

                    List.add(stack.pop());
                }
                if (stack.peek().equals('(')) {
                    stack.pop();
                }


            } else {

                List.add(c);
            }

        }
        while (!stack.isEmpty()) {

            List.add(stack.pop());
        }

         StringBuffer result = new StringBuffer(1000000);

        for (int i = 0; i < List.size(); i++){
            result.append(List.get(i));
            result.append(" ");

        }
     String result1 = result.toString();

        return result1;
    }



    public boolean isoperator(char o) {

        if (o == '+' || o == '-' || o == '*' || o == '/') {

        }

        return true;
    }



}


